package com.iwdnb.gkgz.common.utils;

import java.math.BigDecimal;

import com.iwdnb.gkgz.common.model.dto.StockDayData;

public class KlineUtils {

    /**
     * 是否是锤子线
     *
     * @param data
     * @return
     */
    public static boolean isHammer(StockDayData data) {
        if (data.getClosePrice().compareTo(data.getMinPrice()) == 0) {
            return false;
        }
        BigDecimal entityRange = data.getOpenPrice().subtract(data.getClosePrice()).abs();
        BigDecimal downPrice = data.getOpenPrice().compareTo(data.getClosePrice()) > 0 ? data.getClosePrice()
            : data.getOpenPrice();

        BigDecimal downLineRange = downPrice.subtract(data.getMinPrice());
        BigDecimal rate = downLineRange.divide(entityRange, 1, BigDecimal.ROUND_HALF_UP);
        //下影线是实体形态的2倍
        if (rate.compareTo(new BigDecimal(2)) <= 0) {
            return false;
        }
        BigDecimal upPrice = data.getOpenPrice().compareTo(data.getClosePrice()) > 0 ? data.getOpenPrice()
            : data.getClosePrice();
        BigDecimal upLineRange = data.getMaxPrice().subtract(upPrice);

        BigDecimal upRate = upLineRange.divide(entityRange, 1, BigDecimal.ROUND_HALF_UP);
        //上影线是实体形态的0.7倍以内
        if (upRate.compareTo(new BigDecimal(0.7)) > 0) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        StockDayData data = new StockDayData();
        data.setOpenPrice(new BigDecimal(10));
        data.setClosePrice(new BigDecimal(9.9));
        data.setMaxPrice(new BigDecimal(10.05));
        data.setMinPrice(new BigDecimal(9.6));
        System.out.println(isHammer(data));
    }
}
